package com.cskaoyan.search.service.impl;

import com.cskaoyan.search.converter.ProductConverter;
import com.cskaoyan.search.remote.ProductApiClient;
import com.cskaoyan.search.repository.ProductRepository;
import com.cskaoyan.search.service.InitDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author raccoon@littleraccoon.xyz
 * @since 2022/12/12 19:39
 */
@Service
public class InitDataServiceImpl implements InitDataService {
    @Autowired
    ProductRepository productRepository;
    @Autowired
    ProductConverter productConverter;
    @Autowired
    ProductApiClient productApiClient;


    @Override
    public void initItems() {
        productRepository.saveAll(productConverter.items2Documnets(productApiClient.getAllProductItem().getCallData()));
    }
}
